<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
      @submit.native.prevent
    >
      <el-form-item label="商家名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商家名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="shopShopList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商家名称" align="center" prop="name" />
      <el-table-column
        label="商家简介"
        align="center"
        prop="introduce"
        width="120"
      />
      <el-table-column label="门店电话" align="center" prop="mobile" />
      <el-table-column
        label="营业时间"
        align="center"
        prop="startAt"
        width="80"
      />
      <el-table-column label="规模" align="center" prop="subheading" />
      <el-table-column label="门店地址" align="center" prop="address" />
      <el-table-column label="营业资质" align="center" prop="shareImg">
        <template slot-scope="scope">
          <img
            :src="scope.row.shareImg"
            alt=""
            style="width: 70px; height: 70px"
          />
        </template>
      </el-table-column>
      <el-table-column label="店铺LOGO" align="center" prop="img">
        <template slot-scope="scope">
          <img :src="scope.row.img" alt="" style="width: 70px; height: 70px" />
        </template>
      </el-table-column>
      <el-table-column label="负责人姓名" align="center" prop="coordinate" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="状态" align="center" prop="check">
        <template slot-scope="scope">
          <span>{{
            scope.row.check == 0
              ? "审核中"
              : scope.row.check == 1
              ? "审核通过"
              : "审核失败"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="未通过提示" align="center" prop="tips" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['shop:shopShop:edit']"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改店铺用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="商家名称" prop="name">
          <el-input
            v-model="form.name"
            placeholder="请输入商家名称"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="商家简介" prop="introduce">
          <el-input v-model="form.introduce" placeholder="请输入商家简介" />
        </el-form-item>
        <el-form-item label="门店电话" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入门店电话" />
        </el-form-item>
        <el-form-item label="营业时间" prop="startAt">
          <el-input v-model="form.startAt" placeholder="请输入营业时间" />
        </el-form-item>
        <el-form-item label="规模" prop="subheading">
          <el-input v-model="form.subheading" placeholder="请输入规模" />
        </el-form-item>
        <el-form-item label="门店地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入门店地址" />
        </el-form-item>
        <el-form-item label="营业资质" prop="shareImg">
          <img :src="form.shareImg" alt="" style="width: 70px; height: 70px" />
        </el-form-item>
        <el-form-item label="店铺LOGO" prop="img" label-width="85px">
          <img :src="form.img" alt="" style="width: 70px; height: 70px" />
        </el-form-item>
        <el-form-item label="负责人姓名" prop="coordinate" label-width="85px">
          <el-input v-model="form.coordinate" placeholder="请输入负责人姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="未通过提示" prop="tips">
          <el-input v-model="form.tips" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="状态" prop="phone">
          <el-radio-group v-model="form.check">
            <el-radio :label="0">审核中</el-radio>
            <el-radio :label="1">审核通过</el-radio>
            <el-radio :label="2">审核失败</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listShopShop,
  getShopShop,
  addShopShop,
  updateShopShop,
  exportShopShop,
} from "@/api/mall/shopShop";
export default {
  name: "ShopShop",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺用户表格数据
      shopShopList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        shopId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      //   rules: {
      //     introduce: [
      //       { required: true, message: "用户昵称不能为空", trigger: "blur" },
      //     ],
      //     email: [
      //       { required: true, message: "请输入邮箱地址", trigger: "blur" },
      //       {
      //         type: "email",
      //         message: "请输入正确的邮箱地址",
      //         trigger: ["blur", "change"],
      //       },
      //     ],
      //     phone: [
      //       { required: true, message: "请输入手机号", trigger: "blur" },
      //       {
      //         pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/,
      //         message: "请输入正确的手机号码或者座机号",
      //       },
      //     ],
      //   },
    };
  },
  created() {
    // var shopId = this.$route.query.shopId;
    // this.queryParams.shopId = shopId;
    this.getList();
  },
  methods: {
    /** 查询店铺用户列表 */
    getList() {
      this.loading = true;
      listShopShop(this.queryParams).then((response) => {
        this.shopShopList = response.rows;
        console.log(this.shopShopList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        shopId: null,
        name: null,
        nickName: null,
        userType: null,
        email: null,
        phone: null,
        sex: null,
        delFlag: null,
        serverId: null,
        loginIp: null,
        loginDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.suserId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加店铺用户";
      this.form.shopId = this.queryParams.shopId;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getShopShop(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改店铺用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateShopShop(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addShopShop(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有店铺用户数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportShopShop(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
